package org.blankie.model.soft;

import java.io.InputStream;
import java.util.logging.Logger;
import java.util.logging.Level;

public class SoftwareBuilder {

    private static final Logger logger = Logger.getLogger(SoftwareBuilder.class.getName());

    private Blankie blankie;

    private MavenId mavenId;

    private SoftwareRelease release;

    private SoftwareTier tier;

    public SoftwareBuilder() {
        super();
    }

    public Blankie getBlankie() {
        if (blankie == null) {
            blankie = new Blankie();
            blankie.setMavenId(getMavenId());
            blankie.setRelease(getRelease());
            blankie.setTier(getTier());
        }

        assert blankie != null;
        return blankie;
    }

    protected MavenId getMavenId() {
        if (mavenId == null) {
            String artifactId = "unknown";
            String groupId = "unknown";

            try {
                ClassLoader classLoader = this.getClass().getClassLoader();
            } catch (SecurityException e) {
                logger.log(Level.INFO, "Maven properties file inaccessible", e);
            }
            
            mavenId = new MavenId();
            mavenId.setArtifactId(artifactId);
            mavenId.setGroupId(groupId);
        }

        assert mavenId != null;
        return mavenId;
    }

    protected SoftwareRelease getRelease() {
        if (release == null) {
            release = new SoftwareRelease();
            release.setBeta(true);
        }

        assert release != null;
        return release;
    }

    protected SoftwareTier getTier() {
        if (tier == null) {
            tier = new SoftwareTier();
        }

        assert tier != null;
        return tier;
    }

}
